package com.gdpu.project.service.impl;

import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.LinkedMap;

import com.gdpu.page.vo.ScoreIndex;
import com.gdpu.project.dao.CgConferenceDao;
import com.gdpu.project.dao.CgInnovateDao;
import com.gdpu.project.dao.CgPatentDao;
import com.gdpu.project.dao.CgProjectDao;
import com.gdpu.project.dao.CgThesisDao;
import com.gdpu.project.dao.CgTreatiseDao;
import com.gdpu.project.service.ScoreCheck;
import com.gdpu.project.vo.CgConference;
import com.gdpu.project.vo.CgInnovate;
import com.gdpu.project.vo.CgPatent;
import com.gdpu.project.vo.CgProject;
import com.gdpu.project.vo.CgThesis;
import com.gdpu.project.vo.CgTreatise;
import com.gdpu.project.vo.Teacher;

public class ScoreCheckImpl implements ScoreCheck{
	private CgConferenceDao cgconference;
	private CgInnovateDao cginnovate;
	private CgPatentDao cgpatent;
	private CgProjectDao cgproject;
	private CgThesisDao cgthesis;
	private CgTreatiseDao cgtreatise;
	
	public CgConferenceDao getCgconference() {
		return cgconference;
	}



	public void setCgconference(CgConferenceDao cgconference) {
		this.cgconference = cgconference;
	}



	public CgInnovateDao getCginnovate() {
		return cginnovate;
	}



	public void setCginnovate(CgInnovateDao cginnovate) {
		this.cginnovate = cginnovate;
	}



	public CgPatentDao getCgpatent() {
		return cgpatent;
	}



	public void setCgpatent(CgPatentDao cgpatent) {
		this.cgpatent = cgpatent;
	}



	public CgProjectDao getCgproject() {
		return cgproject;
	}



	public void setCgproject(CgProjectDao cgproject) {
		this.cgproject = cgproject;
	}



	public CgThesisDao getCgthesis() {
		return cgthesis;
	}



	public void setCgthesis(CgThesisDao cgthesis) {
		this.cgthesis = cgthesis;
	}



	public CgTreatiseDao getCgtreatise() {
		return cgtreatise;
	}



	public void setCgtreatise(CgTreatiseDao cgtreatise) {
		this.cgtreatise = cgtreatise;
	}



	@Override
	public List<ScoreIndex> search(List<Teacher> teacher,Date startTime,Date endTime) {
		Iterator<Teacher> iteartor = teacher.iterator();
		List<ScoreIndex> scorelist = new LinkedList<ScoreIndex>();
		while(iteartor.hasNext()){
			Teacher t = iteartor.next();
			String  teacherId = t.getTeacherId();
			
			//List<CgConference> conference = this.cgconference.findByTeacherId(teacherId).getResultlist();
			List<CgConference> conferenceList = this.cgconference.nfindByProperty("teacherId", teacherId, startTime, endTime);
			Iterator<CgConference> cf = conferenceList.iterator();
			while(cf.hasNext()){
				CgConference c = cf.next();
				ScoreIndex score = new ScoreIndex();
				score.setAuthor(c.getConferenceName());
				score.setCategory("学术会议");
				score.setName(c.getConferenceName());
				score.setScore(Float.toString(c.getKeYanFen()));
				scorelist.add(score);
			}
			
			//List<CgInnovate> innovate = cginnovate.findByTeacherId(teacherId).getResultlist();
			List<CgInnovate> innovate = cginnovate.nfindByProperty("teacherId", teacherId, startTime, endTime);
			Iterator<CgInnovate> ci = innovate.iterator();
			while(ci.hasNext()){
				CgInnovate c = ci.next();
				ScoreIndex score = new ScoreIndex();
				score.setAuthor(c.getTeacherName());
				score.setLevel(c.getPrizeLevel());
				score.setName(c.getInnovateName());
				score.setCategory("科技创新");
				score.setScore(Float.toString(c.getKeYanFen()));
				scorelist.add(score);
			}
			
			//List<CgPatent> patent = cgpatent.findByTeacherId(teacherId).getResultlist();
			List<CgPatent> patent = cgpatent.nfindByProperty("teacherId", teacherId, startTime, endTime);
			Iterator<CgPatent> cp = patent.iterator();
			while(cp.hasNext()){
				CgPatent c = cp.next();
				ScoreIndex score = new ScoreIndex();
				score.setAuthor(c.getFuZeRen());
				score.setCategory("专利");
				score.setLevel(c.getPublishRange());
				score.setName(c.getPatentTitle());
				score.setScore(Float.toString(c.getKeYanFen()));
				scorelist.add(score);
			}
			
			//List<CgProject> project = cgproject.findByTeacherId(teacherId).getResultlist();
			List<CgProject> project = cgproject.nfindByProperty("teacherId", teacherId, startTime, endTime);
			Iterator<CgProject> cj = project.iterator();
			while(cj.hasNext()){
				CgProject c = cj.next();
				ScoreIndex score = new ScoreIndex();
				score.setAuthor(c.getFuZeRen());
				score.setCategory("成果项目");
				score.setLevel(c.getResearchType());
				score.setName(c.getProjectName());
				score.setScore(Float.toString(c.getKeYanFen()));
				scorelist.add(score);
			}
			
			//List<CgThesis> thesis = cgthesis.findByTeacherId(teacherId).getResultlist();
			List<CgThesis> thesis = cgthesis.nfindByProperty("teacherId", teacherId, startTime, endTime);
			Iterator<CgThesis> ct = thesis.iterator();
			while(ct.hasNext()){
				CgThesis c = ct.next();
				ScoreIndex score = new ScoreIndex();
				score.setAuthor(c.getTeacherName());
				score.setCategory("论文");
				score.setLevel(c.getGrade());
				score.setName(c.getThesisTitle());
				score.setScore(Float.toString(c.getKeYanFen()));
				scorelist.add(score);
			}
			
			//List<CgTreatise> treatise = cgtreatise.findByTeacherId(teacherId).getResultlist();
			List<CgTreatise> treatise = cgtreatise.nfindByProperty("teacherId", teacherId, startTime, endTime);
			Iterator<CgTreatise> cr = treatise.iterator();
			while(cr.hasNext()){
				CgTreatise c = cr.next();
				ScoreIndex score = new ScoreIndex();
				score.setCategory("专著");
				score.setAuthor(c.getTeacherName());
//				score.setAuthor(c.getEditorRole()!=null?c.getTeacherName()+"("+c.getEditorRole()+")":c.getTeacherName());
				score.setLevel(c.getPressLevel());
				score.setName(c.getTreatiseTitle());
				score.setScore(Float.toString(c.getKeYanFen()));
				scorelist.add(score);
			}
		}
		return scorelist;
	}
	
	
}
